package com.haopt.quartz.demo;

import org.quartz.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author haopt
 * @version 1.0
 * @ClassName MainConfig
 * @Description TODO
 * @date 2021/5/10 12:05
 */

@Configuration
public class MainConfig {

    /**
     * 产生JobDetail对象
     * @return
     */
    @Bean
    public JobDetail jobDetail() {
        return JobBuilder.newJob(MyJob.class)
                //JobDetail表示，自己随便定义
                .withIdentity("myJob", "group1")
                .storeDurably()
                .build();
    }

    /**
     * 产生Trigger对象
     * @param jobDetail
     * @return
     */
    @Bean
    public Trigger trigger1(JobDetail jobDetail) {
        return TriggerBuilder.newTrigger()
                //Trigger标识，自己随意定义
                .withIdentity("trigger1", "group1")
                .startNow()
                //书写corn表达式
                .withSchedule(CronScheduleBuilder.cronSchedule("0/5 * * * * ?"))
                //关联JobDetail对象
                .forJob(jobDetail)
                .build();
    }

}
